﻿<?php

if($_SERVER['SERVER_NAME'] == "127.0.0.1"){
    $mysql_host = "127.0.0.1";
    $mysql_host_s = "127.0.0.1";
    $mysql_user = "root";
    $mysql_password = "root";
    $mysql_database = "doucube";
}
else if ($_SERVER["SERVER_NAME"] == "discuz.comli.com"){
    $mysql_host = "mysql6.000webhost.com";
    $mysql_host_s = "mysql6.000webhost.com";
    $mysql_user = "a2751502_user2";
    $mysql_password = "taojin1021";
    $mysql_database = "a2751502_weixin";
}
else {
    $mysql_host = SAE_MYSQL_HOST_M;
    $mysql_host_s = SAE_MYSQL_HOST_S;  //sae的从库
    $mysql_user = SAE_MYSQL_USER;
    $mysql_password = SAE_MYSQL_PASS;
    $mysql_database =  SAE_MYSQL_DB;
}
    
function replaceUserRecord($userWxid, $cityCode)
{
    Global $mysql_host;
    Global $mysql_host_s;
    Global $mysql_user;
    Global $mysql_password;
    Global $mysql_database;
    
	$mysql_table = "location";
    //REPLACE INTO location (userWxid, cityCode) VALUES("oIDrpjqASyTPnxRmpS9O_ruZGsfk","101010100");
	$mysql_state = "REPLACE INTO ".$mysql_table." (userWxid, cityCode) VALUES(\"".$userWxid."\",\"".$cityCode."\");";
	$con = mysql_connect($mysql_host, $mysql_user, $mysql_password);
	if (!$con){
		die('Could not connect: ' . mysql_error());
	}
	mysql_query("SET NAMES 'UTF8'");
	mysql_select_db($mysql_database, $con);
	$result = mysql_query($mysql_state);
	return $result;
}

function searchUserRecord($userWxid)
{
    Global $mysql_host;
    Global $mysql_host_s;
    Global $mysql_user;
    Global $mysql_password;
    Global $mysql_database;
    
    //查询使用从库，支持SAE
	$mysql_table = "location";
	$mysql_state = "SELECT * FROM ".$mysql_table." WHERE userWxid = \"".$userWxid."\"";
	$con = mysql_connect($mysql_host_s, $mysql_user, $mysql_password);
	if (!$con){
		die('Could not connect: ' . mysql_error());
	}
	mysql_query("SET NAMES 'UTF8'");
	mysql_select_db($mysql_database, $con);
	$result = mysql_query($mysql_state);
    $citylist = array(); 
    while($row = mysql_fetch_array($result))
    {
        $citylist[] = $row["cityCode"]; 
    }
	mysql_close($con);
	return current($citylist);
}

function emptyUserRecord()
{
    Global $mysql_host;
    Global $mysql_host_s;
    Global $mysql_user;
    Global $mysql_password;
    Global $mysql_database;
    
	$mysql_table = "location";
	$mysql_state = "DELETE FROM ".$mysql_table.";";
	$con = mysql_connect($mysql_host, $mysql_user, $mysql_password);
	if (!$con){
		die('Could not connect: ' . mysql_error());
	}
	mysql_query("SET NAMES 'UTF8'");
	mysql_select_db($mysql_database, $con);
	$result = mysql_query($mysql_state);
	return $result;
}

?>